<template>
  <div>
    <van-nav-bar safe-area-inset-top placeholder :title="$t('Data')" left-arrow fixed @click-left="onClickLeft" />

    <van-pull-refresh v-model="isLoading" :pulling-text="$t('PullingText')" :loosing-text="$t('PullingText')" :success-text="$t('refreshSuccee')" @refresh="onRefresh">
      <div class="dataBox">
        <van-collapse v-model="activeNames">
          <van-collapse-item :title="$t('Solar')" name="1">
            <van-cell :title="$t('PV1Voltage')" :value="pv1Voltage | numFilter(1,'V')" />
            <van-cell :title="$t('PV2Voltage')" :value="pv2Voltage | numFilter(1,'V')" />
            <van-cell :title="$t('PV3Voltage')" :value="pv3Voltage | numFilter(1,'V')" v-if="inverterType==10||inverterType==11||inverterType==12||inverterType==13||inverterType==16" />
            <van-cell :title="$t('PV4Voltage')" :value="pv4Voltage | numFilter(1,'V')" v-if="inverterType==10||inverterType==11||inverterType==12" />
            <van-cell :title="$t('PV5oltage')" :value="pv5Voltage | numFilter(1,'V')" v-if="inverterType==100" />
            <van-cell :title="$t('PV6Voltage')" :value="pv6Voltage | numFilter(1,'V')" v-if="inverterType==100" />
            <van-cell :title="$t('PV7Voltage')" :value="pv7Voltage | numFilter(1,'V')" v-if="inverterType==100" />
            <van-cell :title="$t('PV8Voltage')" :value="pv8Voltage | numFilter(1,'V')" v-if="inverterType==100" />
            <van-cell :title="$t('PV9Voltage')" :value="pv9Voltage | numFilter(1,'V')" v-if="inverterType==100" />
            <van-cell :title="$t('PV10Voltage')" :value="pv10Voltage | numFilter(1,'V')" v-if="inverterType==100" />
            <van-cell :title="$t('PV11Voltage')" :value="pv11Voltage | numFilter(1,'V')" v-if="inverterType==100" />
            <van-cell :title="$t('PV12Voltage')" :value="pv12Voltage | numFilter(1,'V')" v-if="inverterType==100" />
            <van-cell :title="$t('PV1Current')" :value="pv1Current | numFilter(1,'A')" />
            <van-cell :title="$t('PV2Current')" :value="pv2Current | numFilter(1,'A')" />
            <van-cell :title="$t('PV3Current')" :value="pv3Current | numFilter(1,'A')" v-if="inverterType==10||inverterType==11||inverterType==12||inverterType==13||inverterType==16" />
            <van-cell :title="$t('PV4Current')" :value="pv4Current | numFilter(1,'A')" v-if="inverterType==10||inverterType==11||inverterType==12" />
            <van-cell :title="$t('PV5Current')" :value="pv5Current | numFilter(1,'A')" v-if="inverterType==100" />
            <van-cell :title="$t('PV6Current')" :value="pv6Current | numFilter(1,'A')" v-if="inverterType==100" />
            <van-cell :title="$t('PV7Current')" :value="pv7Current | numFilter(1,'A')" v-if="inverterType==100" />
            <van-cell :title="$t('PV8Current')" :value="pv8Current | numFilter(1,'A')" v-if="inverterType==100" />
            <van-cell :title="$t('PV9Current')" :value="pv9Current | numFilter(1,'A')" v-if="inverterType==100" />
            <van-cell :title="$t('PV10Current')" :value="pv10Current | numFilter(1,'A')" v-if="inverterType==100" />
            <van-cell :title="$t('PV11Current')" :value="pv11Current | numFilter(1,'A')" v-if="inverterType==100" />
            <van-cell :title="$t('PV12Current')" :value="pv12Current | numFilter(1,'A')" v-if="inverterType==100" />
            <van-cell :title="$t('PV1InputPower')" :value="pv1InputPower | numFilter(1,'W')" />
            <van-cell :title="$t('PV2InputPower')" :value="pv2InputPower | numFilter(1,'W')" />
            <van-cell :title="$t('PV3InputPower')" :value="pv3InputPower | numFilter(1,'W')" v-if="inverterType==10||inverterType==11||inverterType==12||inverterType==13||inverterType==16" />
            <van-cell :title="$t('PV4InputPower')" :value="pv4InputPower | numFilter(1,'W')" v-if="inverterType==10||inverterType==11||inverterType==12" />
            <van-cell :title="$t('PV5InputPower')" :value="pv5InputPower | numFilter(1,'W')" v-if="inverterType==100" />
            <van-cell :title="$t('PV6InputPower')" :value="pv6InputPower | numFilter(1,'W')" v-if="inverterType==100" />
            <van-cell :title="$t('PV7InputPower')" :value="pv7InputPower | numFilter(1,'W')" v-if="inverterType==100" />
            <van-cell :title="$t('PV8InputPower')" :value="pv8InputPower | numFilter(1,'W')" v-if="inverterType==100" />
            <van-cell :title="$t('PV9InputPower')" :value="pv9InputPower | numFilter(1,'W')" v-if="inverterType==100" />
            <van-cell :title="$t('PV10InputPower')" :value="pv10InputPower | numFilter(1,'W')" v-if="inverterType==100" />
            <van-cell :title="$t('PV11InputPower')" :value="pv11InputPower | numFilter(1,'W')" v-if="inverterType==100" />
            <van-cell :title="$t('PV12InputPower')" :value="pv12InputPower | numFilter(1,'W')" v-if="inverterType==100" />
          </van-collapse-item>
          <van-collapse-item :title="$t('PowerGrid')" name="2">
            <van-cell :title="$t('ConsumeEnergy')" :value="consumeEnergy | numFilter(1,'kWh')" v-if="inverterType!=100" />
            <van-cell :title="$t('GridPower')" :value="gridPower | numFilter(1,'W')" />
            <van-cell :title="$t('FeedInEnergy')" :value="feedInEnergy | numFilter(1,'kWh')" v-if="inverterType!=100" />
          </van-collapse-item>
          <van-collapse-item :title="$t('EPS')" name="3" v-if="inverterType!=4&&inverterType!=6&&inverterType!=7&&inverterType!=8&&inverterType!=9&&inverterType!=16&&inverterType!=100">
            <van-cell :title="$t('EPSVoltage1')" :value="epsVoltage1 | numFilter(1,'V')" />
            <van-cell :title="$t('EPSVoltage2')" :value="epsVoltage2 | numFilter(1,'V')" v-if="inverterType==5||inverterType==13||inverterType==14" />
            <van-cell :title="$t('EPSVoltage3')" :value="epsVoltage3 | numFilter(1,'V')" v-if="inverterType==5||inverterType==14" />
            <van-cell :title="$t('EPSCurrent1')" :value="epsCurrent1 | numFilter(1,'A')" />
            <van-cell :title="$t('EPSCurrent2')" :value="epsCurrent2 | numFilter(1,'A')" v-if="inverterType==5||inverterType==13||inverterType==14" />
            <van-cell :title="$t('EPSCurrent3')" :value="epsCurrent3 | numFilter(1,'A')" v-if="inverterType==5||inverterType==14" />
            <van-cell :title="$t('EPSPower1')" :value="epsPower1 | numFilter(1,'W')" />
            <van-cell :title="$t('EPSPower2')" :value="epsPower2 | numFilter(1,'W')" v-if="inverterType==5||inverterType==13||inverterType==14" />
            <van-cell :title="$t('EPSPower3')" :value="epsPower3 | numFilter(1,'W')" v-if="inverterType==5||inverterType==14" />
          </van-collapse-item>
          <van-collapse-item :title="$t('Battery')" name="4" v-if="inverterType!=4&&inverterType!=6&&inverterType!=7&&inverterType!=8&&inverterType!=16&&inverterType!=100">
            <van-cell :title="$t('BatteryCapacity')" :value="batteryCapacity | numFilter(1,'%')" />
            <van-cell :title="$t('BatteryVoltage')" :value="batteryVoltage | numFilter(1,'V')" />
            <van-cell :title="$t('BatteryPower')" :value="batteryPower | numFilter(1,'W')" />
            <van-cell :title="$t('Temperature')" :value="batteryTemperature | numFilter(1,'℃')" />
          </van-collapse-item>
          <van-collapse-item :title="$t('About')" name="5">
            <van-cell :title="$t('InverterSN')" :value="Invertersn | ifNull" />
            <van-cell :title="$t('DSPVersion')" :value="DSPVersion | ifNull" />
            <van-cell :title="$t('ARMVersion')" :value="ARMVersion | ifNull" />
          </van-collapse-item>
        </van-collapse>
      </div>
    </van-pull-refresh>
  </div>
</template>

<script>
export default {
  data(){
    return {
      isLoading:false,
      activeNames:[],
      bdPwd:sessionStorage.getItem('bdPwd'),
      inverterType:localStorage.getItem('inverterType'),
      transportType:localStorage.getItem('transportType'),
      pv1Voltage:'',
      pv2Voltage:'',
      pv3Voltage:'',
      pv4Voltage:'',
      pv1Current:'',
      pv2Current:'',
      pv3Current:'',
      pv4Current:'',
      pv1InputPower:'',
      pv2InputPower:'',
      pv3InputPower:'',
      pv4InputPower:'',
      consumeEnergy:'',
      gridPower:'',
      feedInEnergy:'',
      epsVoltage1:'',
      epsVoltage2:'',
      epsVoltage3:'',
      epsCurrent1:'',
      epsCurrent2:'',
      epsCurrent3:'',
      epsPower1:'',
      epsPower2:'',
      epsPower3:'',
      batteryCapacity:'',
      batteryVoltage:'',
      batteryPower:'',
      batteryTemperature:'',
      Invertersn:'',
      DSPVersion:'',
      ARMVersion:''
    }
  },
  methods: {
    onClickLeft(){
      this.$router.push({path:'/localin'});
    },
    async getInfors(){
      this.comm.loadingShow();
      let data = await this.SETAPI.LocalIn({'optType':'ReadRealTimeData','pwd':this.bdPwd});
      if(data!=null||data!=undefined){
        if(this.transportType==1||this.inverterType>=8){
          this.getPub2(data['Data'],data['Information']);
        }else{
          this.getPub1(data['Data'],data['Information']);
        }
      }else{
        this.comm.tipsShow('InvNoResponse');
      }
    },
    //非透传
    getPub1(datas,Info){
      //光伏
      this.pv1Voltage=datas[2];
      this.pv2Voltage=datas[3];
      this.pv1Current=datas[0];
      this.pv2Current=datas[1];
      this.pv1InputPower=datas[11];
      this.pv2InputPower=datas[12];
      //Grid
      this.consumeEnergy=datas[42];
      this.gridPower=datas[6];
      this.feedInEnergy=datas[41];
      //EPS
      this.epsVoltage1=datas[53];
      this.epsVoltage2=datas[87];
      this.epsVoltage3=datas[90];
      this.epsCurrent1=datas[54];
      this.epsCurrent2=datas[88];
      this.epsCurrent3=datas[91];
      this.epsPower1=datas[55];
      this.epsPower2=datas[89];
      this.epsPower3=datas[92];
      //Battery
      this.batteryCapacity=datas[21];
      this.batteryVoltage=datas[13];
      this.batteryPower=datas[15];
      this.batteryTemperature=datas[16];
      //About
      this.Invertersn=Info[3];
      this.DSPVersion=Info[5];
      this.ARMVersion=Info[7];
    },
    //透传
    getPub2(datas,Info){
      let newDatas=this.invAdres.getRealTimeData(this.inverterType,datas);
      //光伏
      this.pv1Voltage=newDatas.Vdc1.value;
      this.pv2Voltage=newDatas.Vdc2.value;
      this.pv3Voltage=newDatas.Vdc3.value;
      this.pv4Voltage=newDatas.Vdc4.value;
      this.pv5Voltage=newDatas.Vdc5.value;
      this.pv6Voltage=newDatas.Vdc6.value;
      this.pv7Voltage=newDatas.Vdc7.value;
      this.pv8Voltage=newDatas.Vdc8.value;
      this.pv9Voltage=newDatas.Vdc9.value;
      this.pv10Voltage=newDatas.Vdc10.value;
      this.pv11Voltage=newDatas.Vdc11.value;
      this.pv12Voltage=newDatas.Vdc12.value;
      this.pv1Current=newDatas.Idc1.value;
      this.pv2Current=newDatas.Idc2.value;
      this.pv3Current=newDatas.Idc3.value;
      this.pv4Current=newDatas.Idc4.value;
      this.pv5Current=newDatas.Idc5.value;
      this.pv6Current=newDatas.Idc6.value;
      this.pv7Current=newDatas.Idc7.value;
      this.pv8Current=newDatas.Idc8.value;
      this.pv9Current=newDatas.Idc9.value;
      this.pv10Current=newDatas.Idc10.value;
      this.pv11Current=newDatas.Idc11.value;
      this.pv12Current=newDatas.Idc12.value;
      this.pv1InputPower=newDatas.PowerDc1.value;
      this.pv2InputPower=newDatas.PowerDc2.value;
      this.pv3InputPower=newDatas.PowerDc3.value;
      this.pv4InputPower=newDatas.PowerDc4.value;
      this.pv5InputPower=newDatas.PowerDc5.value;
      this.pv6InputPower=newDatas.PowerDc6.value;
      this.pv7InputPower=newDatas.PowerDc7.value;
      this.pv8InputPower=newDatas.PowerDc8.value;
      this.pv9InputPower=newDatas.PowerDc9.value;
      this.pv10InputPower=newDatas.PowerDc10.value;
      this.pv11InputPower=newDatas.PowerDc11.value;
      this.pv12InputPower=newDatas.PowerDc12.value;
      //Grid
      this.consumeEnergy=newDatas.ConsumeEnergy.value;
      this.gridPower=newDatas.GridAPower.value+newDatas.GridBPower.value+newDatas.GridCPower.value;
      this.feedInEnergy=newDatas.FeedInEnergy.value;
      //EPS
      this.epsVoltage1=newDatas.EPSAVoltage.value;
      this.epsVoltage2=newDatas.EPSBVoltage.value;
      this.epsVoltage3=newDatas.EPSCVoltage.value;
      this.epsCurrent1=newDatas.EPSACurrent.value;
      this.epsCurrent2=newDatas.EPSBCurrent.value;
      this.epsPower1=newDatas.EPSAPower.value;
      this.epsPower2=newDatas.EPSBPower.value;
      this.epsCurrent3=newDatas.EPSCCurrent.value;
      this.epsPower3=newDatas.EPSCPower.value;
      //Battery
      this.batteryCapacity=newDatas.BatteryCapacity.value;
      this.batteryVoltage=newDatas.BatteryVoltage.value;
      this.batteryPower=newDatas.BAT_Power.value;
      this.batteryTemperature=newDatas.BatteryTemperature.value;
      //About
      this.Invertersn=Info[2];
      this.DSPVersion=Info[4];
      this.ARMVersion=Info[6];
    },
    onRefresh(){
      this.isLoading=false;
      this.getInfors();
    }
  },
  mounted(){
    setTimeout(()=>{
      this.getInfors();
    },1000);
  }
}
</script>

<style scoped lang="less">
.dataBox{
  text-align: left;
}
</style>
